package com.fs.sys.web;

import com.fs.sys.service.AppLoginService;
import com.fs.sys.bean.dto.UserDTO;
import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 应用登录<br/>
 * 采用code换算的方式，跳转到应用时，生成code并带上传给应用，应用调用门户接口解析用户信息并换算成自己系统内token；<br/>
 * 当应用系统认证过期时，可带上redirectUri跳转到门户登录页面，门户登录后即带code跳转到指定的页面；
 *
 * @author LiuQi 2025/6/10-9:22
 * @version V1.0
 **/
@RestController
@RequestMapping("/sys/app/auth")
public class AppLoginController {
    @Autowired
    private AppLoginService appLoginService;

    @GetMapping("code")
    public String getCode() {
        return appLoginService.getCode();
    }

    @GetMapping("user-info")
    @PermitAll
    public UserDTO getUserInfo(@RequestParam("code") String code) {
        return appLoginService.parseUserInfo(code);
    }
}
